package cn.edu.scau.cmi.yejiancong.abstractFactory.client;





import cn.edu.scau.cmi.yejiancong.abstractFactory.abstractCompany.PICCinsuranceFactory;
import cn.edu.scau.cmi.yejiancong.abstractFactory.abstractCompany.PingAninsurancefactory;
import cn.edu.scau.cmi.yejiancong.abstractFactory.abstractCompany.abstractCompany;
import cn.edu.scau.cmi.yejiancong.abstractFactory.insurance.insurance;
import cn.edu.scau.cmi.yejiancong.simplefactory.man;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.SplitMenuButton;
import javafx.scene.control.TextArea;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.canvas.Canvas;

public class viewController {
	@FXML
	private  BorderPane paner;
	@FXML
	private  Label nameLaber;
	@FXML
	private  Label numberLaber;
	@FXML
	private  ChoiceBox insure;
	@FXML
	private  AnchorPane apane;
	@FXML
	private  Button showBut;
	@FXML
	private TextArea information;
	@FXML
	private RadioButton Picc;
	@FXML 
	private RadioButton PingAn;
	
	final ToggleGroup group=new ToggleGroup();
	
	public void init() {
		man yjc=new man();
		insurance insurance=null;
		
		Picc.setToggleGroup(group);
		PingAn.setToggleGroup(group);
		
		nameLaber.setText(yjc.getName());
		numberLaber.setText(yjc.getNumber().toString());
		
		Image image =new Image(getClass().getResourceAsStream("yjc.jpg"));
		ImageView imageView = new ImageView();
		
		imageView.setImage(image);
		imageView.setFitHeight(100);
		imageView.setFitWidth(100);
		paner.setCenter(imageView);
		insure.setItems(FXCollections.observableArrayList(
			    "bodyInjur", "carBroke", "peopleDamge","otherCase"));
		
	}

	public void show() {

		

		
		
		insure.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
			public void changed(ObservableValue ov,Number value,Number newval) {
				int flag=-1;
				if(Picc.equals(group.getSelectedToggle())) flag=1;
				else if(PingAn.equals(group.getSelectedToggle())) flag=2;
				System.out.println(flag);
				abstractCompany abstractCompany=new PICCinsuranceFactory();
				abstractCompany abstractCompany2=new PingAninsurancefactory();
				insurance inse=null;
				if(flag==1)
				{
					inse=abstractCompany.PICCinsuranceType(newval.intValue());
					information.setText("PICC "+inse.information());
				}
				else if(flag==2)
				{
					inse=abstractCompany2.PingAninsuranceType(newval.intValue());
					information.setText("PingAn "+inse.information());
				}
			}
		});
		
	}
	

}
